//
//  JimDelightHashTable.h
//  CollectionTest
//
//  Created by Dusan Vujosevic on 2013-10-27.
//  Copyright (c) 2013 Suavetech. All rights reserved.
//

#ifndef __CollectionTest__JimDelightHashTable__
#define __CollectionTest__JimDelightHashTable__

#include "CollectionBase.h"
#include <set>

template <typename Tkey>
class STBucket
{
public:
	void AddElem(Tkey& elem);
	bool ContainsElem(const Tkey& elem) const;
	
private:
	std::set<Tkey> _elems;
};

class JimDelightHashTable: public CollectionBase
{
public:
	JimDelightHashTable(size_t elementCountHint);
	virtual ~JimDelightHashTable();

	virtual const char* name() const { return "JimDelightHashTable"; }

	// Reset, return to intial (clean) state, mandatory
	virtual void reset();
	
	// Load the collection, mandatory, timed
	virtual void loadElements(const void* randBytes, size_t elemCount);
	
	// Random search, mandatory, timed
	virtual bool findElement(elemType elem);

private:
	size_t hash(const elemType& elem) const { return (size_t)elem & _mask; }
	
	elemType _mask;
	size_t _tableSize;
	STBucket<elemType>* _table;
};

#endif /* defined(__CollectionTest__JimDelightHashTable__) */
